home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
msdos
/
raytrace
/
pov
/
gen
/
xtal4pov
/
xtal4pov.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-10
|
20KB
|
714 lines
/* Crystal Shape Generator for POVRay 2.x, Ver. 2.0 */
/* Klaus Kosten Inst. f. Kristallographie der RWTH Aachen 22.05.94 */
#include "STDIO.H"
#include "MATH.H"
#define True 1
#define False 0
FILE *daten;
void klasse_lesen(void);
void lesen(void);
void laden(void);
void erzeugen(void);
void pruefen(void);
void skalieren(void);
void hextrans(void);
void monotrans(void);
void tritrans(void);
void notrans(void);
void anfang(void);
void schreiben(void);
void ende(void);
/* Tabelle der Punktgruppen */
short int MatAnz;
short int krsys;
short int Temp[3];
short int Generator[5][3][3];
short int Form[48][3];
short int Zeiger, h, i, j, k, l, m;
short int Flag, Klasse, *PGMat;
char PGr[6], PG[16];
float b, c, d, e, f, scale;
float OutForm[48][3];
main() {
printf("XTAL4POV 2.0\n");
printf("Crystal Shape Generator for POV-Ray 2.x\n\n");
printf("K. Kosten Institut für Kristallographie RWTH Aachen ");
printf(" 22.05.94 \n\n\n");
/* Kristallklasse lesen und Matrix erzeugen */
klasse_lesen();
laden();
anfang();
do {
for(h=0; h<48; h++) { /* Form initialisieren */
for(i=0; i<3; i++) {
Form[h][i] = 0;
}
}
lesen(); /* Miller-Indices laden */
if (Form[0][0] >= 99)
break;
Zeiger = 1;
Flag = False;
if (MatAnz > 0) {
erzeugen();
}
switch (krsys) {
case 1: tritrans();
break;
case 2: monotrans();
break;
case 5:
case 6: hextrans();
break;
default : notrans();
}
skalieren();
for (h = 0; h < Zeiger; h++) {
for (i = 0; i < 3; i++) {
printf("%6d", Form[h][i]);
}
printf("\n");
}
printf("%d Faces calculated\n\n", Zeiger);
printf("Crystal Class: %s\n", PGr);
printf("Scale factor: %8.4f\n", scale);
schreiben();
} while(Form[0][0] < 99);
ende();
}
void klasse_lesen(void) {
printf("The following crystal class symbols may be used:\n\n");
printf("Triclinic:\t1\t-1\n");
printf("Monoclinic:\t2\tm\t2/m\n");
printf("Orthorhombic:\t222\tmm2\tmmm\n");
printf("Tetragonal:\t4\t-4\t4/m\t422\t4mm\t-42m\t4/mmm\n");
printf("Trigonal:\t3\t-3\t32\t3m\t-3m\n");
printf("Hexagonal:\t6\t-6\t6/m\t622\t6mm\t-62m\t6/mmm\n");
printf("Cubic:\t\t23\tm-3\t432\t-43m\tm-3m\n\n");
printf("Please enter a symbol: ");
gets(PGr);
}
void lesen(void) {
printf("\n\nPlease enter the Miller-Indices\n ");
printf("Format: h k l\n\n");
printf("( 99 0 0 ends ):\n");
scanf("%d %d %d", &h, &k, &l);
Form[0][0] = h;
Form[0][1] = k;
Form[0][2] = l;
}
void skalieren(void) {
b = fabs(OutForm[0][0]);
c = fabs(OutForm[0][1]);
d = fabs(OutForm[0][2]);
scale = sqrt( (b * b) + (c * c) + (d * d) );
e = (b > c ? b : c);
f = (e > d ? e : d);
scale /= f;
scale = 1 / scale;
}
void hextrans(void) {
float trans[3][3];
float b;
for (h = 0; h < 3; h++) {
for (i = 0; i < 3; i++) {
trans[h][i] = 0;
}
}
trans[0][0] = 1;
trans[0][1] = -.5;
trans[1][1] = .866;
trans[2][2] = 1;
for (h = 0; h < Zeiger; h++) {
for (i = 0; i < 3; i++) {
b = 0;
for (j = 0; j < 3; j++) {
b += Form[h][j] * trans[i][j];
}
OutForm[h][i] = b;
}
}
}
void monotrans(void) {
notrans();
}
void tritrans(void) {
notrans();
}
void notrans(void) {
for (h = 0; h < Zeiger; h++) {
for (i = 0; i < 3; i++) {
OutForm[h][i] = Form[h][i];
}
}
}
void erzeugen(void) {
do {
l = Zeiger;
for (m = 0; m < MatAnz; m++) {
for(j=0; j < Zeiger; j++) { /* Matrixmultiplikation */
for (h = 0; h < 3; h++) {
Temp[h] = 0;
}
for(h=0; h<3; h++) {
for(i=0; i<3; i++) {
Temp[h] += ( Generator[m][h][i] * Form[j][i] ) ;
}
}
Flag = False;
pruefen();
if ( Flag == False ) {
for (h=0; h<3; h++) {
Form[Zeiger][h] = Temp[h];
}
Zeiger++;
}
}
}
} while (l < Zeiger);
}
void pruefen(void) {
for(k=0; k < Zeiger; k++) { /* Wert vorhanden ? */
i = 0;
for(h=0; h<3; h++) {
if ( Temp[h] == Form[k][h] )
i++;
}
if (i == 3) {
Flag = True;
}
}
}
void anfang(void) {
daten = fopen ("crystal.inc","w");
fprintf(daten, "/* Crystal Data for POVRay 2.x\n");
fprintf(daten, " Generated by XTAL4POV 2.0\n\n");
fprintf(daten, " Crystal Class %s\n", PGr);
fprintf(daten, "*/\n\n\n\n");
}
void schreiben(void) {
strcpy (PG, PGr);
strcat (PG, "_");
for (h = 0; h < 16; h++)
{ if (PG[h] == '-') PG[h] = '_';
}
fprintf(daten, "#declare %s", PG);
for (h = 0; h < 3; h++) {
k = abs(Form[0][h]);
if (Form[0][h] < 0) {
fprintf (daten, "_");
}
fprintf (daten, "%d", k);
}
fprintf (daten, " = intersection {\n");
for (h = 0; h < Zeiger; h++) {
fprintf(daten, "\tplane { < ");
fprintf(daten, " %6.3f,", OutForm[h][0]);
fprintf(daten, " %6.3f,", OutForm[h][1]);
fprintf(daten, " %6.3f", OutForm[h][2]);
fprintf(daten, " >, %6.3f }\n", scale);
}
fprintf(daten, "\n}\n\n\n");
}
void ende(void) {
fclose(daten);
printf("Crystal data were written to file CRYSTAL.INC\n\n");
}
/* Definition of generator matrices */
static short int PGGen2[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen3[] =
{ -1, 0, 0, 0, 1, 0, 0, 0, -1
};
static short int PGGen4[] =
{ 1, 0, 0, 0, -1, 0, 0, 0, 1
};
static short int PGGen5[] =
{ -1, 0, 0, 0, 1, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen6[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1
};
static short int PGGen7[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
1, 0, 0, 0, -1, 0, 0, 0, 1
};
static short int PGGen8[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen9[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, 1, 0, 0, 0, 0, 1
};
static short int PGGen10[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, 1, 0, -1, 0, 0, 0, 0, -1
};
static short int PGGen11[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, 1, 0, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen12[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, 1, 0, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1
};
static short int PGGen13[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, 1, 0, 0, 0, 0, 1,
1, 0, 0, 0, -1, 0, 0, 0, 1
};
static short int PGGen14[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, 1, 0, -1, 0, 0, 0, 0, -1,
-1, 0, 0, 0, 1, 0, 0, 0, -1
};
static short int PGGen15[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, 1, 0, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen16[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1
};
static short int PGGen17[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 1, 0, -1, 0, 0, 0, 0, 1
};
static short int PGGen18[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
0, -1, 0, -1, 0, 0, 0, 0, -1
};
static short int PGGen19[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
0, -1, 0, -1, 0, 0, 0, 0, 1
};
static short int PGGen20[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
0, -1, 0, -1, 0, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen21[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, 1
};
static short int PGGen22[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
1, 0, 0, 0, 1, 0, 0, 0, -1
};
static short int PGGen23[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen24[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, 1,
0, 1, 0, 1, 0, 0, 0, 0, -1
};
static short int PGGen25[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, 1,
0, -1, 0, -1, 0, 0, 0, 0, 1
};
static short int PGGen26[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
1, 0, 0, 0, 1, 0, 0, 0, -1,
0, -1, 0, -1, 0, 0, 0, 0, 1
};
static short int PGGen27[] =
{ 0, -1, 0, 1, -1, 0, 0, 0, 1,
-1, 0, 0, 0, -1, 0, 0, 0, 1,
0, 1, 0, 1, 0, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen28[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
0, 0, 1, 1, 0, 0, 0, 1, 0
};
static short int PGGen29[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
0, 0, 1, 1, 0, 0, 0, 1, 0,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
static short int PGGen30[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
0, 0, 1, 1, 0, 0, 0, 1, 0,
0, 1, 0, 1, 0, 0, 0, 0, -1
};
static short int PGGen31[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
0, 0, 1, 1, 0, 0, 0, 1, 0,
0, 1, 0, 1, 0, 0, 0, 0, 1
};
static short int PGGen32[] =
{ -1, 0, 0, 0, -1, 0, 0, 0, 1,
-1, 0, 0, 0, 1, 0, 0, 0, -1,
0, 0, 1, 1, 0, 0, 0, 1, 0,
0, 1, 0, 1, 0, 0, 0, 0, -1,
-1, 0, 0, 0, -1, 0, 0, 0, -1
};
void laden(void) {
if (strcmp(PGr, "1") == 0) Klasse = 1;
if (strcmp(PGr, "-1") == 0) Klasse = 2;
if (strcmp(PGr, "2") == 0) Klasse = 3;
if (strcmp(PGr, "m") == 0) Klasse = 4;
if (strcmp(PGr, "2/m") == 0) Klasse = 5;
if (strcmp(PGr, "222") == 0) Klasse = 6;
if (strcmp(PGr, "mm2") == 0) Klasse = 7;
if (strcmp(PGr, "mmm") == 0) Klasse = 8;
if (strcmp(PGr, "4") == 0) Klasse = 9;
if (strcmp(PGr, "-4") == 0) Klasse = 10;
if (strcmp(PGr, "4/m") == 0) Klasse = 11;
if (strcmp(PGr, "422") == 0) Klasse = 12;
if (strcmp(PGr, "4mm") == 0) Klasse = 13;
if (strcmp(PGr, "-42m") == 0) Klasse = 14;
if (strcmp(PGr, "4/mmm") == 0) Klasse = 15;
if (strcmp(PGr, "3") == 0) Klasse = 16;
if (strcmp(PGr, "-3") == 0) Klasse = 17;
if (strcmp(PGr, "32") == 0) Klasse = 18;
if (strcmp(PGr, "3m") == 0) Klasse = 19;
if (strcmp(PGr, "-3m") == 0) Klasse = 20;
if (strcmp(PGr, "6") == 0) Klasse = 21;
if (strcmp(PGr, "-6") == 0) Klasse = 22;
if (strcmp(PGr, "6/m") == 0) Klasse = 23;
if (strcmp(PGr, "622") == 0) Klasse = 24;
if (strcmp(PGr, "6mm") == 0) Klasse = 25;
if (strcmp(PGr, "-62m") == 0) Klasse = 26;
if (strcmp(PGr, "6/mmm") == 0) Klasse = 27;
if (strcmp(PGr, "23") == 0) Klasse = 28;
if (strcmp(PGr, "m-3") == 0) Klasse = 29;
if (strcmp(PGr, "432") == 0) Klasse = 30;
if (strcmp(PGr, "-43m") == 0) Klasse = 31;
if (strcmp(PGr, "m-3m") == 0) Klasse = 32;
/* Definitionstabelle der Punktgruppen */
switch (Klasse) {
case 1 : /* (1) 1 */
MatAnz = 0;
krsys = 1;
break;
case 2 : /* (2) -1 */
MatAnz = 1;
krsys = 1;
PGMat = &PGGen2[0];
break;
case 3 : /* (3) 2 */
MatAnz = 1;
krsys = 2;
PGMat = &PGGen3[0];
break;
case 4 : /* (4) m */
MatAnz = 1;
krsys = 2;
PGMat = &PGGen4[0];
break;
case 5 : /* (5) 2/m */
MatAnz = 2;
krsys = 2;
PGMat = &PGGen5[0];
break;
case 6 : /* (6) 222 */
MatAnz = 2;
krsys = 3;
PGMat = &PGGen6[0];
break;
case 7 : /* (7) mm2 */
MatAnz = 2;
krsys = 3;
PGMat = &PGGen7[0];
break;
case 8 : /* (8) mmm */
MatAnz = 3;
krsys = 3;
PGMat = &PGGen8[0];
break;
case 9 : /* (9) 4 */
MatAnz = 2;
krsys = 4;
PGMat = &PGGen9[0];
break;
case 10 : /* (10) -4 */
MatAnz = 2;
krsys = 4;
PGMat = &PGGen10[0];
break;
case 11 : /* (11) 4/m */
MatAnz = 3;
krsys = 4;
PGMat = &PGGen11[0];
break;
case 12 : /* (12) 422 */
MatAnz = 3;
krsys = 4;
PGMat = &PGGen12[0];
break;
case 13 : /* (13) 4mm */
MatAnz = 3;
krsys = 4;
PGMat = &PGGen13[0];
break;
case 14 : /* (14) -42m */
MatAnz = 3;
krsys = 4;
PGMat = &PGGen14[0];
break;
case 15 : /* (15) 4/mmm */
MatAnz = 4;
krsys = 4;
PGMat = &PGGen15[0];
break;
case 16 : /* (16) 3 */
MatAnz = 1;
krsys = 5;
PGMat = &PGGen16[0];
break;
case 17 : /* (17) -3 */
MatAnz = 2;
krsys = 5;
PGMat = &PGGen17[0];
break;
case 18 : /* (18) 32 */
MatAnz = 2;
krsys = 5;
PGMat = &PGGen18[0];
break;
case 19 : /* (19) 3m */
MatAnz = 2;
krsys = 5;
PGMat = &PGGen19[0];
break;
case 20 : /* (20) -3m */
MatAnz = 3;
krsys = 5;
PGMat = &PGGen20[0];
break;
case 21 : /* (21) 6 */
MatAnz = 2;
krsys = 6;
PGMat = &PGGen21[0];
break;
case 22 : /* (22) -6 */
MatAnz = 2;
krsys = 6;
PGMat = &PGGen22[0];
break;
case 23 : /* (23) 6/m */
MatAnz = 3;
krsys = 6;
PGMat = &PGGen23[0];
break;
case 24 : /* (24) 622 */
MatAnz = 3;
krsys = 6;
PGMat = &PGGen24[0];
break;
case 25 : /* (25) 6mm */
MatAnz = 3;
krsys = 6;
PGMat = &PGGen25[0];
break;
case 26 : /* (26) -6m2 */
MatAnz = 3;
krsys = 6;
PGMat = &PGGen26[0];
break;
case 27 : /* (27) 6/mmm */
MatAnz = 4;
krsys = 6;
PGMat = &PGGen27[0];
break;
case 28 : /* (28) 23 */
MatAnz = 3;
krsys = 7;
PGMat = &PGGen28[0];
break;
case 29 : /* (29) m-3 */
MatAnz = 4;
krsys = 7;
PGMat = &PGGen29[0];
break;
case 30 : /* (30) 432 */
MatAnz = 4;
krsys = 7;
PGMat = &PGGen30[0];
break;
case 31 : /* (31) -43m */
MatAnz = 4;
krsys = 7;
PGMat = &PGGen31[0];
break;
case 32 : /* (32) m-3m */
MatAnz = 5;
krsys = 7;
PGMat = &PGGen32[0];
}
/* Generatormatrix erzeugen */
if (MatAnz > 0)
{ for (h = 0; h < MatAnz; h++) /* Generator laden */
{ for(i = 0; i < 3; i++)
{ for(j = 0; j < 3; j++)
{ Generator [h][i][j] = *(PGMat+(h*9)+(i*3)+j);
}
}
}
}
}